package com.fit.pianosheetshop.pages;

import org.apache.tapestry5.annotations.*;
import org.apache.tapestry5.annotations.SessionState;
import org.apache.tapestry5.ioc.annotations.Inject;



import com.fit.pianosheetshop.interfaces.*;
import com.fit.pianosheetshop.service.Sheets;

public class ViewSheet {
	@Inject
	@Property
	private Sheets sheets;

	@Property
	private Sheet currentSheet;

	@InjectPage
	private SheetDetails sheetDetailsPage;
	

	@InjectPage
	private EntryBorrow entryBorrow;

	@OnEvent(component = "sheetDetailsLink")
	Object onShowDetails(String title) {
		Sheet chosenSheet = sheets.retrieveSingleSheet(title);
		sheetDetailsPage.setChosenSheet(chosenSheet);
		return sheetDetailsPage;
}
	
	@OnEvent(component = "entrySheetLink")
	Object onSheetLink(String title) {
		entryBorrow.setBorrowSheet(title);
		return entryBorrow;
	}
	
	@SessionState
	private User user;

	private boolean userExists;
	
	public User getUser() {
		return user;
	}
	
	Object onActivate() {
		if (!userExists) return Login.class;
		return null;
	}
}